/**
 * ClassName 流程挂接视图
 * */
var numStore = new Ext.data.SimpleStore
({
    fields: ["id", "pageSize"],
    data: [
        ['5', 5],
        ['10', 10],
        ['20', 20],
        ['50', 50]
    ]
});
Ext.define("core.salesorder.view.SalesOrderGrid", {
    extend: "Ext.grid.Panel",
    alias: "widget.salesordergrid",
    store: "core.salesorder.store.SalesOrderStore",
    selModel: {
        selType: "checkboxmodel"
    },
    border: 0,
    multiSelect: true,
    viewConfig: {
        enableTextSelection: true//单元格内容可以被选中，便于复制
    },
    frame: true,
    tbar: [
        {
            xtype: 'button', text: '刷新', ref: 'refresh', iconCls: 'table_refresh',
            handler: function (btn) {
//				var store = btn.ownerCt.ownerCt.getStore();
//				store.clearFilter(false);
            }
        },
        {xtype: 'panel', width: 15, border: 0},
        '按定客户查询:',
        {
            xtype: 'triggerfield',
            triggerCls: Ext.baseCSSPrefix + 'form-search-trigger',
            listeners: {
                "change": function (_this, _new, _old, _opt) {
                    var _store = _this.ownerCt.ownerCt.getStore();
                    _store.clearFilter(false);
                    _store.filter("username", _new);
                }
            },
            onTriggerClick: function () {
                var _store = this.ownerCt.ownerCt.getStore();
                _store.clearFilter(false);
                _store.filter("username", this.getValue());
            }
        },

        {xtype: 'panel', width: 15, border: 0},
        '按定单编号查询:',
        {
            xtype: 'triggerfield',
            triggerCls: Ext.baseCSSPrefix + 'form-search-trigger',
            listeners: {
                "change": function (_this, _new, _old, _opt) {
                    var _store = _this.ownerCt.ownerCt.getStore();
                    _store.clearFilter(false);
                    _store.filter("orderId", _new);
                }
            },
            onTriggerClick: function () {
                var _store = this.ownerCt.ownerCt.getStore();
                _store.clearFilter(false);
                _store.filter("orderId", this.getValue());
            }
        },
        {xtype: 'panel', width: 15, border: 0},
        {
            xtype: 'combobox', width: 175,
            fieldLabel: '请选择过滤条件',
            store: Ext.create('Ext.data.Store', {
                fields: ['abbr', 'name'],
                data: [
                    {"abbr": "quanbu", "name": "全部"},
                    {"abbr": "1", "name": "审核"},
                    {"abbr": "0", "name": "未审核"}
                    //...
                ]
            }),
            queryMode: 'local',
            displayField: 'name',
            valueField: 'abbr',
            value: '全部',
            listeners: {
                scope: this,
                'select': function (combo, record) {
                    var store = combo.ownerCt.ownerCt.getStore();
                    if (record[0].data.abbr == "quanbu") {
                        store.clearFilter(false);
                    } else {
                        store.clearFilter(false);
                        store.filter("status", record[0].data.abbr);
                    }
                    //store.clearFilter(false);
                    //alert(record[0].data.name);
                }
            }

        },
        "->",
        '提示：查看详细情况请双击记录'
    ],
    bbar: {
        xtype: 'pagingtoolbar',
        store: 'core.salesorder.store.SalesOrderStore',
        dock: 'bottom',
        totalProperty: "totalProperty",
        displayInfo: true,
        items: [
            {
                xtype: 'combobox',
                width: 45,
                forceSelection: true,
                mode: 'local',
                store: numStore,
                displayField: 'id',
                valueField: 'pageSize',
                id: 'pageSize',
                value: 10
            }]

    },
    enableKeyNav: true,  //可以使用键盘控制上下
    columnLines: true, //展示竖线
    columns: [
        {xtype: 'rownumberer'},
        {text: "定单编号", dataIndex: "orderId", width: 100},
        {text: "客户名", dataIndex: "username", width: 70},
        {
            text: "状态", dataIndex: "status", width: 80,
            renderer: function (v) {
                if (v == "1") {
                    return '<font color=red>已审核</font>';
                } else if (v == "0") {
                    return '<font color=green>未审核</font>';//
                }
            }
        },
        {
            text: "作废", dataIndex: "nullify", width: 80,
            renderer: function (v) {
                if (v == "1") {
                    return '<font color=red>正常</font>';
                } else if (v == "0") {
                    return '<font color=green>已作废</font>';//
                }
            }
        },
        {
            text: "总金额", dataIndex: "totalmoney", width: 80,
            xtype: 'numbercolumn',
            summaryType: 'sum',
            summaryRenderer: function (value, summaryData, dataIndex) {
                return Ext.String.format('总和:' + value);
            },
            renderer: function (v) {
                if (v >= 1000.00) {
                    return "<font color=red size= 2><B>" + v + "</B></font>";
                } else {
                    return "<font color=blue  size= 2><B>" + v + "</B></font>";
                }
            },
            format: '0.00'
        },
        {text: "下定单日期", dataIndex: "ordDate", width: 150},
        {text: "电话", dataIndex: "phone", width: 100},
        {text: "QQ", dataIndex: "qq", width: 80},
        {text: "送货地址", dataIndex: "address", width: 240},
        {text: "备注", dataIndex: "remark", width: 100}
    ],
    initComponent: function () {
        this.callParent(arguments);
    }
});